<?php
include'../King/hero.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='login.php';</script>");
?>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title><?php echo $conf['sitename']; ?>-添加我的站点</title>
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <link rel="stylesheet" type="text/css" href="css/materialdesignicons.min.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <!--表格插件css-->
    <link rel="stylesheet" href="js/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" type="text/css" href="css/style.min.css">
    <!--对话框插件css-->
    <link rel="stylesheet" type="text/css" href="js/jquery-confirm/jquery-confirm.min.css">
    <link rel="stylesheet" type="text/css" href="css/style.min.css">
    <style>
        .big-img {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100vh;
            -webkit-background-color: rgba(0, 0, 0, .5);
            background-color: rgba(0, 0, 0, .5);
            display: block;
            z-index: 999;
            display: none;
        }

        .big-img img {
            position: absolute;
            left: 50%;
            top: 50%;
            -webkit-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
            font-size: 0;
            width: 42vw;
            -webkit-transition: transform .3s;
            transition: transform .3s;
        }

        .big-img::after {
            content: '×';
            position: absolute;
            right: 4em;
            top: 1.5em;
            width: 3.5em;
            height: 3.5em;
            font-size: 3.5em;
            color: #fff;
        }
        
        .layui-layer-content .input-group-addon {
            margin-right: 1.5em;
        }

        @media screen and (max-width: 501px) {
            .big-img::after {
                top: 3em;
            }

            .big-img img {
                width: 95vw;
            }
        }
    </style>
</head>

<body>

    <div class="container-fluid">

        <div class="row">

            <div class="col-lg-12">
                <div class="card">
                    <header class="card-header">
                        <div class="card-title">添加我的站点</div>
                    </header>
                    <div class="card-body">

                        <div class="bootstrap-table bootstrap5">
                            <div class="fixed-table-toolbar">
                                <div class="bs-bars float-left">
                                    <div id="toolbar" class="toolbar-btn-action">
                                        <button onclick="adda()" type="button" class="btn btn-primary me-1">
                                            <span class="mdi mdi-plus" aria-hidden="true"></span>新增
                                        <button onclick="xulie(1)" type="button" class="btn btn-primary me-1">
                                            正序
                                        </button>
                                        <button onclick="xulie(0)" type="button" class="btn btn-primary me-1">
                                            倒序
                                        </button>
                                          <button onclick="delall()" type="button" class="btn btn-warning me-1">
                                            全部删除
                                        </button>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <div class="fixed-table-container" style="padding-bottom: 0px;">
                                <div class="fixed-table-header" style="display: none;">
                                    <table></table>
                                </div>
                                <div class="fixed-table-body">
                                    <div class="fixed-table-loading table table-bordered table-hover table-striped lyear-table"
                                        style="top: 50.3739px;">
                                        <span class="loading-wrap">
                                            <span class="loading-text" style="font-size: 32px;">正在努力地加载数据中，请稍候</span>
                                            <span class="animation-wrap"><span class="animation-dot"></span></span>
                                        </span>

                                    </div>
                                    <table id="table"
                                        class="table table-bordered table-hover table-striped lyear-table">
                                        <thead class="">
                                            <tr>
                                                <th style="text-align: center; width: 8rem; " data-field="id">
                                                    <div class="th-inner">编号</div>
                                                    <div class="fht-cell"></div>
                                                </th>
                                                <th title="网站名称" style="text-align: center; " data-field="author">
                                                    <div class="th-inner ">网站名称</div>
                                                    <div class="fht-cell"></div>
                                                </th>
                                                <th style="text-align: center; " data-field="dynasty">
                                                    <div class="th-inner ">跳转链接</div>
                                                    <div class="fht-cell"></div>
                                                </th>
                                                <th style="text-align: center; " data-field="opus">
                                                    <div class="th-inner ">网站图片</div>
                                                    <div class="fht-cell"></div>
                                                </th>
                                                <th style="text-align: center;" data-field="operate">
                                                    <div class="th-inner ">操作</div>
                                                    <div class="fht-cell"></div>
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
if($conf['urlxulie']==1){
$nbm='asc';
}else{
$nbm='desc';
}
$rs=$DB->query("SELECT * FROM xf_url WHERE 1 order by id {$nbm}");
while($res = $DB->fetch($rs))
{             
?>
                    <tr data-num="<?=$res["id"]?>">
                <td style="text-align: center;"><?=$res["id"]?></td>
                <td style="text-align: center; "><?=$res["name"]?></td>
        <td style="text-align: center; "><a href="<?=$res["url"]?> "target="_blank" rel="noopener noreferrer"><?=$res["url"]?></a></td>
                <td style="text-align: center; width: 10rem; cursor: pointer;"><img src="<?=$res["img"]?>" class="img-fluid clickImg"></td>
                <td style="text-align: center;">
                    <a href="#!" class="btn btn-sm btn-default del-btn-site" title="" data-bs-toggle="tooltip" data-bs-original-title="删除"onclick="del(<?=$res["id"]?>)" aria-label="删除"><i class="mdi mdi-window-close"></i>
                    </a>
                </td>
            </tr>
<?php
}
?>
                                            
                                        </tbody>
                                    </table>
                                </div>
                                <div class="fixed-table-footer"></div>
                            </div>
                        </div>
                        <div class="clearfix"></div>

                    </div>
                </div>
            </div>

        </div>

    </div>

    <div class="big-img">
        <img src="../assets/upload/blog_picture.jpg">
    </div>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/popper.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/main.min.js"></script>
    <script type="text/javascript" src="js/fireworks.js"></script>
    <script type="text/javascript" src="js/template-web.js"></script>
    <!--表格插件js-->
    <script src="js/bootstrap-table/bootstrap-table.js"></script>
    <script src="js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <!--对话框插件js-->
    <script type="text/javascript" src="js/jquery-confirm/jquery-confirm.min.js"></script>
    <script type="text/javascript" src="js/main.min.js"></script>

  <script src="//lib.baomitu.com/layer/2.3/layer.js"></script>
    <script>
    var $bigImg = $('.big-img')
    var $clickImg = $('.clickImg')
    $clickImg.on('click', function () {
        $bigImg.fadeIn().children().prop('src', $(this).prop('src'))
    })

    $bigImg.on('click', function (e) {
        if (!$(e.target).is($bigImg.children())) {
            $(this).fadeOut()
        }
    })
  function delall() {
	layer.confirm('你确实要全部删除吗？', {
		btn: ['确定','取消']
		}, function(){
		var ii = layer.load(3, {shade:[0.1,'#fff']});
		$.ajax({
			type : "POST",
			url : "./ajax.php?act=delallurl",
		
			dataType : "json",
			success : function(data) {
				layer.close(ii);
				if(data.code == 0){
					layer.msg(data.msg, {icon: 1});
					window.location.reload();
					}else{
						layer.msg(data.msg, {icon: 2});
						window.location.reload();
					}
					}
					});
			}, function(){
			});
}
    function del(id) {
	layer.confirm('你确实要删除此站点吗？', {
		btn: ['确定','取消']
		}, function(){
		var ii = layer.load(3, {shade:[0.1,'#fff']});
		$.ajax({
			type : "POST",
			url : "./ajax.php?act=delurl",
			data : {id:id},
			dataType : "json",
			success : function(data) {
				layer.close(ii);
				if(data.code == 1){
					layer.msg(data.msg, {icon: 1});
					window.location.reload();
					}else{
						layer.msg(data.msg, {icon: 2});
						window.location.reload();
					}
					}
					});
			}, function(){
			});
    }
function adda() {
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'GET',
		url : 'ajax.php?act=addurla',
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.open({
				  type: 1,
				  title: '添加我的站点',
				  skin: 'layui-layer-rim',
				  success(layero, index) {
				      $(layero).find('.layui-layer-content').addClass('layui-layer-btn layui-layer-btn-'); 
				  },
				  content: data.data
				});
			}else{
				layer.alert(data.msg);
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
}
function add() {
    var name=$("#name").val();
	var img=$("#img").val();
	var url=$("#url").val();
	if (name == '' || img == '' || url == '') {
        layer.msg("禁止留空！",{icon:2,shift:6});
        return false
	}
 $.ajax({
    type: "POST",
    url: "./ajax.php?act=addurl",
    data: {name:name,url:url,img:img},
    dataType: "json",
    success: function(data) {
            
            if (data.code == 1) {
               $.alert({ title: '', content: data.msg});
                window.location.href = data.url;
      } else {
        $.alert({
            title: '',
            content: "添加失败！",
            type: 'red'
        });
        return false;
      }
    }
  });
}

function xulie(id) {
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax.php?act=xuliea',
		data: {id:id},
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 1){
				layer.alert(data.msg);
				window.location.reload();
			}else{
				layer.alert(data.msg);
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
}
</script>
</body>

</html>